package ru.nsu.zolotorevskii.lab2.workers;

import org.junit.Test;
import static org.junit.Assert.*;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;


public class PrintOperationTest {
    @Test
    public void work() {
        Stack<Double> stack = new Stack<>();
        StringWriter writer = new StringWriter(7);
        Map<String, Double> parameters = new HashMap<>();

        stack.push(5.0);

        String[] variablesPrint = {};
        IOperation printBlock = new PrintOperation();
        printBlock.work(stack, variablesPrint, parameters, writer);

        String result = writer.toString();
        assertTrue(result.trim().equalsIgnoreCase("5.0\n".trim()));
    }

    @Test
    public void errorWork() {
        Stack<Double> stack = new Stack<>();
        StringWriter writer = new StringWriter(7);
        Map<String, Double> parameters = new HashMap<>();

        String[] variablesPrint = {};
        IOperation printBlock = new PrintOperation();
        printBlock.work(stack, variablesPrint, parameters, writer);
        String result = writer.toString();
        assertTrue(result.trim().equalsIgnoreCase("".trim()));
    }
}
